<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    *{
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }
    body{
      min-height: 200vh;
      background-color: #000;
    }
    header{
      position: fixed;
      top: 0;
      left: 0;
      width: 100%;
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 40px 100px;
      z-index: 2;
      transition: 0.6s;
    }
    header .logo{
      font-size: 32px;
      color: #fff;
      font-weight: bold;
      text-decoration: none;
      text-transform: uppercase;
      letter-spacing: 2px;
      transition: 0.6s;
    }
    header ul{
      display: flex;
      justify-content: center;
      align-items: center;
    }
    header ul li{
      list-style: none;
    }
    header ul li a{
      margin: 0 15px;
      text-decoration: none;
      color: #fff;
      font-weight: 500;
      letter-spacing: 2px;
      transition: 0.6s;
      word-wrap: normal;
    }
    .banner1{
      position: relative;
      width: 100%;
      height: 100vh;
      background: url('../images/11.jpg') no-repeat;
      background-size: cover;
      background-position: center center;
    }
    .banner2{
      position: relative;
      width: 100%;
      height: 100vh;
      background: url('../images/10.jpg') no-repeat;
      background-size: cover;
      background-position: center center;
    }
    /* 鼠标滚动改变样式 */
    header.sticky{
      padding: 6px 100px;
      background-color: #fff;
    }
    header.sticky .logo,
    header.sticky ul li a{
      color: #000;
    }

  </style>
</head>
<body>
  <header>
    <a href="#" class="logo">logo</a>
    <ul>
      <li><a href="#">探索车型</a></li>
      <li><a href="#">官方商城</a></li>
      <li><a href="#">车主服务</a></li>
      <li><a href="#">科技创新</a></li>
      <li><a href="#">奔驰天下</a></li>
      <li><a href="#">预约品鉴</a></li>
    </ul>
  </header>
  <section class="banner1"></section>
  <section class="banner2"></section>

  <script>
    window.addEventListener('scroll',()=>{
      
      let header=document.querySelector("header")
      // toggle:
      // 第一个参数：添加或删除的类名，有就删无就加
      // 第二个参数：判断是删除还是添加，flase：移除、true：添加
      header.classList.toggle('sticky',window.scrollY>0)
    })
  </script>
</body>
</html>